package org.zzh.service.system.dept;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.zzh.dao.common.PageBean;
import org.zzh.dao.mapper.PeDeptMapper;
import org.zzh.domain.system.dept.PeDept;

import java.util.List;

@Service
public class PeDeptServiceImpl implements PeDeptService {

    @Autowired
    PeDeptMapper peDeptMapper;

    @Override
    public PageBean<PeDept> list(Integer page, Integer pageSize, String name) {
        PageHelper.startPage(page, pageSize);
        PageBean<PeDept> pageBean = new PageBean<>();
        List<PeDept> list = peDeptMapper.list(name);
        PageInfo<PeDept> peDeptPageInfo = new PageInfo<>(list);
        pageBean.setData(peDeptPageInfo.getList());
        pageBean.setTotalCount((int) peDeptPageInfo.getTotal());
        pageBean.setTotalPage(peDeptPageInfo.getPages());
        pageBean.setPage(page);
        pageBean.setPageSize(pageSize);
        return pageBean;
    }

    @Override
    public PeDept findById(String id) {
        return peDeptMapper.findById(id);
    }

    @Override
    public List <PeDept> findParentList() {
        return peDeptMapper.findParentList();
    }

    @Override
    @Transactional
    public void add(PeDept dept) {
        peDeptMapper.add(dept);
    }

    @Override
    @Transactional
    public void update(PeDept dept) {
        peDeptMapper.update(dept);
    }

    @Override
    @Transactional
    public void deleteList(String[] ids) {
        peDeptMapper.deleteList(ids);
    }
}
